import 'reflect-metadata'
export const CONTROLLER_METADATA = 'controller';
export const ROUTE_METADATA = 'method';
export const PARAM_METADATA = 'param';
export type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch';
export type Param = 'params' | 'query' | 'body' | 'headers' | 'cookies';

// console.log(global.item);
let globafn = require("./global/global.variable");

export function GetApiMessage(params: any) {
    globafn.china.push(params);
    global.temp.push(params);
    // global.temp.push(params);
    // console.log(1);
    return function (target: any, name: string, desc: any) {    
        // console.log(target);
        globafn.functionName.push(name)
        global.item.push(name);
        // console.log(target);

        // console.log(temp);
        // console.log(item);
    }

}





// export const GetApiMessage = function(info: string): MethodDecorator {
//   return (target: any, methodName: string, desc: any) => {
//     // 会用到原始函数
//     // Reflect.defineMetadata(HTTP_KEY.Get, { info, fn: desc.value }, desc.value);
//     const preMetadata = Reflect.getMetadata('controller',target,methodName);

//     console.log(preMetadata);
//   }
// }

// export function Controller(path = ''): ClassDecorator {
//     return (target: object) => {
//         Reflect.defineMetadata(CONTROLLER_METADATA, path, target);
//     };
// }

// export function createMethodDecorator(method: HttpMethod = 'get') {
//     return (path = '/'): MethodDecorator =>
//         (target: object, name: string, descriptor: any) => {
//             Reflect.defineMetadata(ROUTE_METADATA, { type: method, path }, descriptor.value);
//         };
// }

// export function createParamDecorator(type: Param) {
//     return (key?: string): ParameterDecorator =>
//         (target: object, name: string, index: number) => {
//             // 这里要注意这里 defineMetadata 挂在 target.name 上
//             // 但该函数的参数有顺序之分，下一个装饰器定义参数后覆盖之前的，所以要用 preMetadata 保存起来
//             const preMetadata =
//                 Reflect.getMetadata(PARAM_METADATA, target, name) || [];
//             const newMetadata = [{ key, index, type }, ...preMetadata];

//             Reflect.defineMetadata(PARAM_METADATA, newMetadata, target, name);
//         };
// }


